#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试用例数据加载模块
"""

import yaml
import os
from typing import List, Dict, Any

def load_yaml_testcases(case_type: str) -> List[Dict[str, Any]]:
    """
    加载YAML格式的测试用例
    
    Args:
        case_type: 用例类型，如 'login_api', 'order_api'
    
    Returns:
        测试用例列表
    """
    yaml_file = os.path.join(os.path.dirname(__file__), 'testcases.yaml')
    
    if not os.path.exists(yaml_file):
        print(f"警告: 测试用例文件不存在: {yaml_file}")
        return []
    
    try:
        with open(yaml_file, 'r', encoding='utf-8') as f:
            data = yaml.safe_load(f)
        
        # 根据用例类型返回对应的测试用例
        if case_type == 'login_api':
            # 返回登录相关的测试用例
            return [data] if data else []
        elif case_type == 'order_api':
            # 返回订单相关的测试用例
            return [data] if data else []
        else:
            print(f"警告: 未知的用例类型: {case_type}")
            return []
            
    except Exception as e:
        print(f"加载测试用例失败: {e}")
        return []

def get_test_data(case_name: str) -> Dict[str, Any]:
    """
    根据用例名称获取测试数据
    
    Args:
        case_name: 用例名称
    
    Returns:
        测试数据字典
    """
    testcases = load_yaml_testcases('login_api')  # 默认加载登录用例
    
    for case in testcases:
        if case.get('case_name') == case_name:
            return case
    
    return {} 